﻿using System;
using System.Text;
using System.Collections.Generic;

namespace LibMSNP.HTTP
{
    public sealed class HTTPResponseHeader : HTTPHeader
    {
        public HTTPResponseHeader(string status, string reason)
            : base(status, reason) { _headers["Set-Cookie"] = string.Empty; }

        #region HTTPPacketHeader Inherited Members

        public override string this[string index]
        {
            get
            {
                return _headers[index];
            }
            set
            {
                _headers[index] = value;
            }
        }

        public override MimeHeaders Headers
        {
            get
            {
                return _headers;
            }
        }

        public override string ToString()
        {
            string temp = this.VERSION + " " + this._firstEntry + " " + this._secondEntry + this.LINE_END;
            foreach (KeyValuePair<string, string> header in _headers)
            {
                if (header.Value != string.Empty)
                    temp += header.Key + ": " + header.Value + this.LINE_END;
            }
            temp += this.LINE_END;
            return temp;
        }

        public override byte[] ToBytes()
        {
            return ASCIIEncoding.ASCII.GetBytes(this.ToString());
        }

        public override string CacheControl
        {
            get { return _headers["Cache-Control"]; }
        }

        public override string Connection
        {
            get { return _headers["Connection"]; }
        }

        public override string Date
        {
            get { return _headers["Date"]; }
        }

        public override string ContentLength
        {
            get { return _headers["Content-Length"]; }
        }

        public override string ContentType
        {
            get { return _headers["Content-Type"]; }
        }

        public override string Server
        {
            get { return _headers["Server"]; }
        }

        #endregion

        public string Reason
        {
            get { return this._secondEntry; }
        }

        public string Status
        {
            get { return this._firstEntry; }
        }

        public string Cookie
        {
            get { return _headers["Set-Cookie"]; }
        }
    }
}